
***************************************************************************************************************
/*
THIS DO-FILE:
	
Gets assisted living status from raw HRS data (Section H (housing))
1. Goes through each year (1998-2014)
2. Defines assisted living as any of:
   -use group meals
   -use transportation services
   -use ADL care
   -use emergency call/check button
   -use nursing services
3. Creates wide file with assisted living dummy "assistedliving_all.dta"
*/
***************************************************************************************************************

clear
set more off

***************************************************************************************************************
use "$rawdata\h98fin\h98sta\H98F_H.dta", clear
*merge on file that has info from last wave for skips
merge 1:m HHID FSUBHH using "$rawdata\h98fin\h98sta\H98PR_R.dta", assert(match) nogen

gen lastyearRC=(F56==5 & F306==1) //hasn't moved and lives in retirement community (from preload)

tab F2840 //part of retirement community/senior citizen housing
rename F2840 RC_liveinnew

gen RC_livein4=(lastyearRC==1 | inlist(RC_liveinnew,1,2,7))

tab F2857 //whether offers group meals
tab F2858 //whether pay extra for group meals
tab F2859 //whether use group meals
rename F2857 RC_meals_offer4
rename F2859 RC_meals_use4

tab F2861 //whether offers transport services
tab F2862 //whether pay extra
tab F2863 //whether use
rename F2861 RC_transport_offer4
rename F2863 RC_transport_use4

tab F2865 //whether offers housekeeping chores
tab F2866 //whether pay extra
tab F2867 //whether use
rename F2865 RC_chores_offer4
rename F2867 RC_chores_use4

tab F2869 //whether offers help with bathing/dressing/eating
tab F2870 //whether pay extra
tab F2871 //whether use
rename F2869 RC_adls_offer4
rename F2871 RC_adls_use4

tab F2877 //whether offers emergency call button/check on residents
tab F2878 //whether pay extra
tab F2879 //whether use
rename F2877 RC_check_offer4
rename F2879 RC_check_use4

tab F2887 //whether offers nursing care or on-site nurse
tab F2888 //whether special resident facility for nursing care
tab F2889 //whether pay extra for nursing care service
tab F2891 //whether use nursing care service
rename F2887 RC_nursecare_offer4
rename F2891 RC_nursecare_use4

tab F2892 //could you live in same unit if need substantial care?

tab1 RC_adls_use4 RC_check_use4 RC_nursecare_use4
count if RC_adls_use4==1 | RC_check_use4==1 | RC_nursecare_use4==1

keep HHID FSUBHH PN RC_*
save "assistedliving4.dta", replace
***************************************************************************************************************

***************************************************************************************************************
clear
use "$rawdata\h00core\h00sta\H00F_H.dta"
*merge on file that has info from last wave for skips
merge 1:m HHID GSUBHH using "$rawdata\h00core\h00sta\H00PR_R.dta", assert(match) nogen

gen lastyearRC=(G56==5 & G306==1) //hasn't moved and lives in retirement community

tab G3158 //part of retirement community/senior citizen housing
rename G3158 RC_liveinnew

gen RC_livein5=(lastyearRC==1 | inlist(RC_liveinnew,1,2,7))

tab G3175 //whether offers group meals
tab G3176 //whether pay extra for group meals
tab G3177 //whether use group meals
rename G3175 RC_meals_offer5
rename G3177 RC_meals_use5

tab G3179 //whether offers transport services
tab G3180 //whether pay extra
tab G3181 //whether use
rename G3179 RC_transport_offer5
rename G3181 RC_transport_use5

tab G3183 //whether offers housekeeping chores
tab G3184 //whether pay extra
tab G3185 //whether use
rename G3183 RC_chores_offer5
rename G3185 RC_chores_use5

tab G3187 //whether offers help with bathing/dressing/eating
tab G3188 //whether pay extra
tab G3189 //whether use
rename G3187 RC_adls_offer5
rename G3189 RC_adls_use5

tab G3195 //whether offers emergency call button/check on residents
tab G3196 //whether pay extra
tab G3197 //whether use
rename G3195 RC_check_offer5
rename G3197 RC_check_use5

tab G3205 //whether offers nursing care or on-site nurse
tab G3206 //whether special resident facility for nursing care
tab G3207 //whether pay extra for nursing care service
tab G3209 //whether use nursing care service
rename G3205 RC_nursecare_offer5
rename G3209 RC_nursecare_use5

tab G3210 //could you live in same unit if need substantial care?

tab1 RC_adls_use5 RC_check_use5 RC_nursecare_use5
count if RC_adls_use5==1 | RC_check_use5==1 | RC_nursecare_use5==1

keep HHID GSUBHH FSUBHH PN RC_*
save "assistedliving5.dta", replace
***************************************************************************************************************


***************************************************************************************************************
clear
use "$rawdata\h02core\h02sta\H02H_H.dta"
*merge on file that has info from last wave for skips
merge 1:1 HHID HSUBHH using "$rawdata\h02core\h02sta\H02PR_H.dta", assert(match) nogen
merge 1:m HHID HSUBHH using "$rawdata\h02core\h02sta\H02PR_R.dta", assert(match) nogen

gen lastyearRC=(HZ024==1 & HX033==5 & HZ089==1) //reinterview and didn't move and lives in retirement community

tab HH101 //part of retirement community/senior citizen housing
rename HH101 RC_liveinnew

gen RC_livein6=(lastyearRC==1 | inlist(RC_liveinnew,1,2,7))

tab HH115 //whether offers group meals
tab HH116 //whether pay extra for group meals
tab HH117 //whether use group meals
rename HH115 RC_meals_offer6
rename HH117 RC_meals_use6

tab HH118 //whether offers transport services
tab HH119 //whether pay extra
tab HH120 //whether use
rename HH118 RC_transport_offer6
rename HH120 RC_transport_use6

tab HH121 //whether offers housekeeping chores
tab HH122 //whether pay extra
tab HH123 //whether use
rename HH121 RC_chores_offer6
rename HH123 RC_chores_use6

tab HH124 //whether offers help with bathing/dressing/eating
tab HH125 //whether pay extra
tab HH126 //whether use
rename HH124 RC_adls_offer6
rename HH126 RC_adls_use6

tab HH127 //whether offers emergency call button/check on residents
tab HH128 //whether pay extra
tab HH129 //whether use
rename HH127 RC_check_offer6
rename HH129 RC_check_use6

tab HH130 //whether offers nursing care or on-site nurse
tab HH131 //whether special resident facility for nursing care
tab HH132 //whether pay extra for nursing care service
tab HH133 //whether use nursing care service
rename HH130 RC_nursecare_offer6
rename HH133 RC_nursecare_use6

tab HH134 //could you live in same unit if need substantial care?

tab1 RC_adls_use6 RC_check_use6 RC_nursecare_use6
count if RC_adls_use6==1 | RC_check_use6==1 | RC_nursecare_use6==1

keep HHID HSUBHH GSUBHH PN RC_*
save "assistedliving6.dta", replace
***************************************************************************************************************

***************************************************************************************************************
clear
use "$rawdata\h04core\h04sta\H04H_H.dta"
*merge on file that has info from last wave for skips
merge 1:1 HHID JSUBHH using "$rawdata\h04core\h04sta\H04PR_H.dta", assert(match) nogen
merge 1:m HHID JSUBHH using "$rawdata\h04core\h04sta\H04PR_R.dta", assert(match) nogen

gen lastyearRC=(JZ024==1 & JX033==5 & JZ144==1) //reinterview and didn't move and lives in retirement community

tab JH101 //part of retirement community/senior citizen housing
rename JH101 RC_liveinnew

gen RC_livein7=(lastyearRC==1 | inlist(RC_liveinnew,1,7))

tab JH115 //whether offers group meals
tab JH116 //whether pay extra for group meals
tab JH117 //whether use group meals
rename JH115 RC_meals_offer7
rename JH117 RC_meals_use7

tab JH118 //whether offers transport services
tab JH119 //whether pay extra
tab JH120 //whether use
rename JH118 RC_transport_offer7
rename JH120 RC_transport_use7

tab JH121 //whether offers housekeeping chores
tab JH122 //whether pay extra
tab JH123 //whether use
rename JH121 RC_chores_offer7
rename JH123 RC_chores_use7

tab JH124 //whether offers help with bathing/dressing/eating
tab JH125 //whether pay extra
tab JH126 //whether use
rename JH124 RC_adls_offer7
rename JH126 RC_adls_use7

tab JH127 //whether offers emergency call button/check on residents
tab JH128 //whether pay extra
tab JH129 //whether use
rename JH127 RC_check_offer7
rename JH129 RC_check_use7

tab JH130 //whether offers nursing care or on-site nurse
tab JH131 //whether special resident facility for nursing care
tab JH132 //whether pay extra for nursing care service
tab JH133 //whether use nursing care service
rename JH130 RC_nursecare_offer7
rename JH133 RC_nursecare_use7

tab JH134 //could you live in same unit if need substantial care?

tab1 RC_adls_use7 RC_check_use7 RC_nursecare_use7
count if RC_adls_use7==1 | RC_check_use7==1 | RC_nursecare_use7==1

keep HHID JSUBHH HSUBHH PN RC_*
save "assistedliving7.dta", replace
***************************************************************************************************************

***************************************************************************************************************
clear
use "$rawdata\h06core\h06sta\H06H_H.dta"
*merge on file that has info from last wave for skips
merge 1:1 HHID KSUBHH using "$rawdata\h06core\h06sta\H06PR_H.dta", assert(match) nogen
merge 1:m HHID KSUBHH using "$rawdata\h06core\h06sta\H06PR_R.dta", assert(match) nogen

gen lastyearRC=(KZ024==1 & KX033==5 & KZ089==1) //reinterview and didn't move and lives in retirement community

tab KH101 //part of retirement community/senior citizen housing
rename KH101 RC_liveinnew

gen RC_livein8=(lastyearRC==1 | inlist(RC_liveinnew,1,7))

tab KH115 //whether offers group meals
tab KH116 //whether pay extra for group meals
tab KH117 //whether use group meals
rename KH115 RC_meals_offer8
rename KH117 RC_meals_use8

tab KH118 //whether offers transport services
tab KH119 //whether pay extra
tab KH120 //whether use
rename KH118 RC_transport_offer8
rename KH120 RC_transport_use8

tab KH121 //whether offers housekeeping chores
tab KH122 //whether pay extra
tab KH123 //whether use
rename KH121 RC_chores_offer8
rename KH123 RC_chores_use8

tab KH124 //whether offers help with bathing/dressing/eating
tab KH125 //whether pay extra
tab KH126 //whether use
rename KH124 RC_adls_offer8
rename KH126 RC_adls_use8

tab KH127 //whether offers emergency call button/check on residents
tab KH128 //whether pay extra
tab KH129 //whether use
rename KH127 RC_check_offer8
rename KH129 RC_check_use8

tab KH130 //whether offers nursing care or on-site nurse
tab KH131 //whether special resident facility for nursing care
tab KH132 //whether pay extra for nursing care service
tab KH133 //whether use nursing care service
rename KH130 RC_nursecare_offer8
rename KH133 RC_nursecare_use8

tab KH134 //could you live in same unit if need substantial care?

tab1 RC_adls_use8 RC_check_use8 RC_nursecare_use8
count if RC_adls_use8==1 | RC_check_use8==1 | RC_nursecare_use8==1

keep HHID KSUBHH JSUBHH PN RC_*
save "assistedliving8.dta", replace
***************************************************************************************************************

***************************************************************************************************************
clear
use "$rawdata\h08core\h08sta\H08H_H.dta"
*merge on file that has info from last wave for skips
merge 1:1 HHID LSUBHH using "$rawdata\h08core\h08sta\H08PR_H.dta", assert(match) nogen
merge 1:m HHID LSUBHH using "$rawdata\h08core\h08sta\H08PR_R.dta", assert(match) nogen

gen lastyearRC9=(LZ024==1 & LX033==5 & LZ089==1) //reinterview and didn't move and lives in retirement community

tab LH101 //part of retirement community/senior citizen housing
rename LH101 RC_liveinnew

gen RC_livein9=(lastyearRC9==1 | inlist(RC_liveinnew,1,7))

tab LH115 //whether offers group meals
tab LH116 //whether pay extra for group meals
tab LH117 //whether use group meals
rename LH115 RC_meals_offer9
rename LH117 RC_meals_use9

tab LH118 //whether offers transport services
tab LH119 //whether pay extra
tab LH120 //whether use
rename LH118 RC_transport_offer9
rename LH120 RC_transport_use9

tab LH121 //whether offers housekeeping chores
tab LH122 //whether pay extra
tab LH123 //whether use
rename LH121 RC_chores_offer9
rename LH123 RC_chores_use9

tab LH124 //whether offers help with bathing/dressing/eating
tab LH125 //whether pay extra
tab LH126 //whether use
rename LH124 RC_adls_offer9
rename LH126 RC_adls_use9

tab LH127 //whether offers emergency call button/check on residents
tab LH128 //whether pay extra
tab LH129 //whether use
rename LH127 RC_check_offer9
rename LH129 RC_check_use9

tab LH130 //whether offers nursing care or on-site nurse
tab LH131 //whether special resident facility for nursing care
tab LH132 //whether pay extra for nursing care service
tab LH133 //whether use nursing care service
rename LH130 RC_nursecare_offer9
rename LH133 RC_nursecare_use9

tab LH134 //could you live in same unit if need substantial care?

tab1 RC_adls_use9 RC_check_use9 RC_nursecare_use9
count if RC_adls_use9==1 | RC_check_use9==1 | RC_nursecare_use9==1

keep HHID LSUBHH KSUBHH PN RC_* lastyearRC9
save "assistedliving9.dta", replace
***************************************************************************************************************

***************************************************************************************************************
clear
use "$rawdata\h10core\h10sta\H10H_H.dta"
*merge on file that has info from last wave for skips
merge 1:1 HHID MSUBHH using "$rawdata\h10core\h10sta\H10PR_H.dta", assert(match) nogen
merge 1:m HHID MSUBHH using "$rawdata\h10core\h10sta\H10PR_R.dta", assert(match) nogen

gen lastyearRC10=(MZ024==1 & MX033==5 & MZ089==1) //reinterview and didn't move and lives in retirement community

tab MH101 //part of retirement community/senior citizen housing
rename MH101 RC_liveinnew

gen RC_livein10=(lastyearRC10==1 | inlist(RC_liveinnew,1,7))

tab MH115 //whether offers group meals
tab MH116 //whether pay extra for group meals
tab MH117 //whether use group meals
rename MH115 RC_meals_offer10
rename MH117 RC_meals_use10

tab MH118 //whether offers transport services
tab MH119 //whether pay extra
tab MH120 //whether use
rename MH118 RC_transport_offer10
rename MH120 RC_transport_use10

tab MH121 //whether offers housekeeping chores
tab MH122 //whether pay extra
tab MH123 //whether use
rename MH121 RC_chores_offer10
rename MH123 RC_chores_use10

tab MH124 //whether offers help with bathing/dressing/eating
tab MH125 //whether pay extra
tab MH126 //whether use
rename MH124 RC_adls_offer10
rename MH126 RC_adls_use10

tab MH127 //whether offers emergency call button/check on residents
tab MH128 //whether pay extra
tab MH129 //whether use
rename MH127 RC_check_offer10
rename MH129 RC_check_use10

tab MH130 //whether offers nursing care or on-site nurse
tab MH131 //whether special resident facility for nursing care
tab MH132 //whether pay extra for nursing care service
tab MH133 //whether use nursing care service
rename MH130 RC_nursecare_offer10
rename MH133 RC_nursecare_use10

tab MH134 //could you live in same unit if need substantial care?

tab1 RC_adls_use10 RC_check_use10 RC_nursecare_use10
count if RC_adls_use10==1 | RC_check_use10==1 | RC_nursecare_use10==1

keep HHID MSUBHH LSUBHH PN RC_* lastyearRC10
save "assistedliving10.dta", replace
***************************************************************************************************************

***************************************************************************************************************
clear
use "$rawdata\h12core\h12sta\H12H_H.dta"
*merge on file that has info from last wave for skips
merge 1:1 HHID NSUBHH using "$rawdata\h12core\h12sta\H12PR_H.dta", assert(match) nogen
merge 1:m HHID NSUBHH using "$rawdata\h12core\h12sta\H12PR_R.dta", assert(match) nogen

gen lastyearRC11=(NZ024==1 & NX033==5 & NZ089==1) //reinterview and didn't move and lives in retirement community

tab NH101 //part of retirement community/senior citizen housing
rename NH101 RC_liveinnew

gen RC_livein11=(lastyearRC11==1 | inlist(RC_liveinnew,1,7))

tab NH115 //whether offers group meals
tab NH116 //whether pay extra for group meals
tab NH117 //whether use group meals
rename NH115 RC_meals_offer11
rename NH117 RC_meals_use11

tab NH118 //whether offers transport services
tab NH119 //whether pay extra
tab NH120 //whether use
rename NH118 RC_transport_offer11
rename NH120 RC_transport_use11

tab NH121 //whether offers housekeeping chores
tab NH122 //whether pay extra
tab NH123 //whether use
rename NH121 RC_chores_offer11
rename NH123 RC_chores_use11

tab NH124 //whether offers help with bathing/dressing/eating
tab NH125 //whether pay extra
tab NH126 //whether use
rename NH124 RC_adls_offer11
rename NH126 RC_adls_use11

tab NH127 //whether offers emergency call button/check on residents
tab NH128 //whether pay extra
tab NH129 //whether use
rename NH127 RC_check_offer11
rename NH129 RC_check_use11

tab NH130 //whether offers nursing care or on-site nurse
tab NH131 //whether special resident facility for nursing care
tab NH132 //whether pay extra for nursing care service
tab NH133 //whether use nursing care service
rename NH130 RC_nursecare_offer11
rename NH133 RC_nursecare_use11

tab NH134 //could you live in same unit if need substantial care?

tab1 RC_adls_use11 RC_check_use11 RC_nursecare_use11
count if RC_adls_use11==1 | RC_check_use11==1 | RC_nursecare_use11==1

keep HHID NSUBHH MSUBHH PN RC_* lastyearRC11
save "assistedliving11.dta", replace
***************************************************************************************************************

***************************************************************************************************************
clear
use "$rawdata\h14core\h14sta\H14H_H.dta"
*merge on file that has info from last wave for skips
merge 1:1 HHID OSUBHH using "$rawdata\h14core\h14sta\H14PR_H.dta", assert(match) nogen
merge 1:m HHID OSUBHH using "$rawdata\h14core\h14sta\H14PR_R.dta", assert(match) nogen

gen lastyearRC12=(OZ024==1 & OX033==5 & OZ089==1) //reinterview and didn't move and lives in retirement community

tab OH101 //part of retirement community/senior citizen housing
rename OH101 RC_liveinnew

gen RC_livein12=(lastyearRC12==1 | inlist(RC_liveinnew,1,7))

tab OH115 //whether offers group meals
tab OH116 //whether pay extra for group meals
tab OH117 //whether use group meals
rename OH115 RC_meals_offer12
rename OH117 RC_meals_use12

tab OH118 //whether offers transport services
tab OH119 //whether pay extra
tab OH120 //whether use
rename OH118 RC_transport_offer12
rename OH120 RC_transport_use12

tab OH121 //whether offers housekeeping chores
tab OH122 //whether pay extra
tab OH123 //whether use
rename OH121 RC_chores_offer12
rename OH123 RC_chores_use12

tab OH124 //whether offers help with bathing/dressing/eating
tab OH125 //whether pay extra
tab OH126 //whether use
rename OH124 RC_adls_offer12
rename OH126 RC_adls_use12

tab OH127 //whether offers emergency call button/check on residents
tab OH128 //whether pay extra
tab OH129 //whether use
rename OH127 RC_check_offer12
rename OH129 RC_check_use12

tab OH130 //whether offers nursing care or on-site nurse
tab OH131 //whether special resident facility for nursing care
tab OH132 //whether pay extra for nursing care service
tab OH133 //whether use nursing care service
rename OH130 RC_nursecare_offer12
rename OH133 RC_nursecare_use12

tab OH134 //could you live in same unit if need substantial care?

tab1 RC_adls_use12 RC_check_use12 RC_nursecare_use12
count if RC_adls_use12==1 | RC_check_use12==1 | RC_nursecare_use12==1

keep HHID OSUBHH NSUBHH PN RC_* lastyearRC12
save "assistedliving12.dta", replace
***************************************************************************************************************

***************************************************************************************************************
*PUT ALL WAVES TOGETHER AND DEFINE ASSISTED LIVING CARE
clear
use assistedliving4.dta
merge 1:1 HHID PN using assistedliving5.dta, gen(m5)
merge 1:1 HHID PN using assistedliving6.dta, gen(m6)
merge 1:1 HHID PN using assistedliving7.dta, gen(m7)
merge 1:1 HHID PN using assistedliving8.dta, gen(m8)
merge 1:1 HHID PN using assistedliving9.dta, gen(m9)
merge 1:1 HHID PN using assistedliving10.dta, gen(m10)
merge 1:1 HHID PN using assistedliving11.dta, gen(m11)
merge 1:1 HHID PN using assistedliving12.dta, gen(m12)

forval x=4/12 {
	gen assliv`x'=(RC_meals_use`x'==1 | RC_transport_use`x'==1 | RC_adls_use`x'==1 | ///
	               RC_check_use`x'==1 | RC_nursecare_use`x'==1)
}
sum assliv*

egen hhidpn=concat(HHID PN)
destring hhidpn, replace
destring HHID, replace
destring PN, replace
save "assistedliving_all.dta", replace

cap erase "assistedliving4.dta"
cap erase "assistedliving5.dta"
cap erase "assistedliving6.dta"
cap erase "assistedliving7.dta"
cap erase "assistedliving8.dta"
cap erase "assistedliving9.dta"
cap erase "assistedliving10.dta"
cap erase "assistedliving11.dta"
cap erase "assistedliving12.dta"
***************************************************************************************************************
